package tests

import (
	"testing"

	"gitcode.com/deyiyangyang/showen-lang/typ"
)

// TestRationalOperations tests the rational number operations
func TestRationalOperations(t *testing.T) {
	// Create a new environment
	env := typ.NewEnvironment()
	typ.DefineBuiltins(env)

	// Define test cases for rational number operations
	testCases := []struct {
		expr     string
		expected string
	}{{
		// Test rational creation and string representation
		expr:     "(/ 1 2)",
		expected: "1/2",
	}, {
		// Test rational addition
		expr:     "(+ 1/2 1/3)",
		expected: "5/6",
	}, {
		// Test rational subtraction
		expr:     "(- 1/2 1/3)",
		expected: "1/6",
	}, {
		// Test rational multiplication
		expr:     "(* 1/2 2/3)",
		expected: "1/3",
	}, {
		// Test rational division
		expr:     "(/ 1/2 1/3)",
		expected: "3/2",
	}, {
		// Test multiple operations
		expr:     "(+ 1/2 (* 1/3 1/4))",
		expected: "7/12",
	}, {
		// Test integer conversion
		expr:     "(+ 1/2 1/2)",
		expected: "1",
	}, {
		// Test negative rationals
		expr:     "(- 1/2)",
		expected: "-1/2",
	}, {
		// Test complex expression
		expr:     "(/ (+ 1/2 1/3) (- 1/4 1/5))",
		expected: "50/3",
	},
	}

	// Run each test case
	for i, tc := range testCases {
		result := EvaluateExpression(t, tc.expr, env)
		if result != tc.expected {
			t.Errorf("Test Case %d: For expression %s, expected %s, got %s", i+1, tc.expr, tc.expected, result)
		} else {
			t.Logf("Test Case %d: Passed - %s evaluated to %s", i+1, tc.expr, result)
		}
	}
}